package com.github.authcloud.client.configure;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;

/**
 * @author : zhaoxuan
 * @version : 1.0
 * @date : 2021/8/19 23:38
 * @description : AuthClientInitConfigure
 */
@Configuration
@ConditionalOnClass(RedisConnectionFactory.class)
public class AuthClientRunnerConfigure {

    @Resource
    private ApplicationContext applicationContext;

    @Value("${spring.application.name}")
    private String serviceName;

    @Bean
    @DependsOn("authRedisTemplate")
    AuthClientCommandLineRunner authClientCommandLineRunner(@Qualifier("authRedisTemplate") RedisTemplate redisTemplate) {
        return new AuthClientCommandLineRunner(serviceName, applicationContext, redisTemplate);
    }
}
